package gui;

import java.io.*;
import java.lang.*;

public class doLZ77_decompress {

    public String doUNLZ77(String inputstring) {
        String outputstring = new String();
        int i;
        for (i = 0; i < inputstring.length() / 3; i++) {
            int matchindex = (int) inputstring.charAt(i * 3);
            int maxmatch = (int) inputstring.charAt(i * 3 + 1);
            int outchar = (int) inputstring.charAt(i * 3 + 2);
            outputstring = outputstring + outputstring.substring(outputstring.length() - matchindex, outputstring.length() - matchindex + maxmatch);
            outputstring = outputstring + ((char) outchar);

        }
        return outputstring;
    }

    public void doDecomress(String InFile, String OutFile) {
        String args[] = new String[2];
        args[0] = InFile;
        args[1] = OutFile;
        try {
            System.out.println("decoding");
            File inputfile = new File(args[0]);
            FileInputStream fileinstream = new FileInputStream(inputfile);
            String inputstring = "";
            int i;
            long length = inputfile.length();
            for (i = 0; i < length; i++) {
                inputstring = inputstring + (char) fileinstream.read();
            }
            fileinstream.close();
            String output = doUNLZ77(inputstring);
            System.out.println(output.length());
            File outputfile = new File(args[1]);
            FileOutputStream fileoutstream = new FileOutputStream(outputfile);
            DataOutputStream dataoutstream = new DataOutputStream(fileoutstream);
            dataoutstream.writeBytes(output);
            dataoutstream.close();
        } catch (Exception e) {
        }
    }
    /*        public static void main(String args[])
    {
    doDecomress(args);
    } */
}
